﻿using System;
using System.Net.Http;
using Grpc.Net.ClientFactory;

namespace K9Nano.RemoteClient.LoadBalancing
{
    internal class RoundRobinGrpcClientFactory : GrpcClientFactory
    {
        private readonly RoundRobinGrpcChannelFactory _robinGrpcChannelFactory;

        public RoundRobinGrpcClientFactory(RoundRobinGrpcChannelFactory robinGrpcChannelFactory)
        {
            _robinGrpcChannelFactory = robinGrpcChannelFactory;
        }

        public override TClient CreateClient<TClient>(string name)
        {
            var channel = _robinGrpcChannelFactory.Create(name);
            return (TClient)Activator.CreateInstance(typeof(TClient), channel);
        }
    }
}